$('.alert').fadeOut(5000);

$(document).ready(function(){

    $(".up-arrow, .down-arrow").hover(
        function() {
            $(this).stop().animate({
                "opacity": "0"
            }, "slow");
        },
        function() {
            $(this).stop().animate({
                "opacity": "1"
            }, "slow");
        }
    );
        
    $("img.up-arrow").click(
        function() {
            var disputeId = $(this).data('id');
            $(".down-arrow[data-id='" + disputeId + "']").show();
            $(".up-arrow[data-id='" + disputeId + "']").hide();
            $("div[id$='" + disputeId + "']").text(
                function(index, text) {
                    return parseInt($(this).data('score'))+1;
                }
            );
            $.ajax({
                url: "/index/xhr-up-vote",
                data: { disputeId: disputeId }
            });
        }
    );
     
    $("img.down-arrow").click(
        function() {
            var disputeId = $(this).data('id');
            $(".up-arrow[data-id='" + disputeId + "']").show();
            $(".down-arrow[data-id='" + disputeId + "']").hide();
            $("div[id$='" + disputeId + "']").text(
                function(index, text) {
                    var score = parseInt($(this).data('score'));
                    return score==0 ? 0 : score-1;
                }
            );
            $.ajax({
                url: "/index/xhr-down-vote",
                data: { disputeId: disputeId }
            });
        }
    );
        
});